<template>
  <view class="home">
    <form-item :formJson="formJson" :is_disabled="is_disabled" remarkShow @handleSubmit="handleSubmit">
    </form-item>
    <back-page></back-page>
  </view>
</template>

<script setup>
  import {
    computed,
    onMounted,
    ref
  } from 'vue';
  import formItem from '@/components/form-item/form-item.vue'
  import { houseOption, sell_house, upload } from '../../../config/api';
  const props = defineProps({
    type: {
      type: String,
      default: 1
    }
  })
  const is_disabled = computed(() => props.type == 2 ? true : false)
  const formJson = ref([{
    label: '期望小区',
    key: 'xiaoqu',
    type: 'text',
    placeholder: "选择周边小区",
    border: true,
    required: true,
  }, {
    label: '楼栋号',
    key: 'lou_num',
    type: 'text',
    border: true,
    required: true,
    placeholder: "请输入楼栋号",
  }, {
    label: '单元门',
    key: 'unit_num',
    type: 'text',
    border: true,
    required: true,
    placeholder: "请输入单元门",
  }, {
    label: '门牌号',
    key: 'house_num',
    type: 'text',
    border: true,
    required: true,
    placeholder: "请输入门牌号",
  }, {
    label: '选择户型',
    key: 'house_type',
    key_text: 'house_type_text',
    type: 'select',
    placeholder: "选择室卫厅",
    border: true,
    required: true,
    selectList: []
  }, {
    label: '楼层',
    key: 'floor',
    type: 'text',
    required: true,
    border: true,
    placeholder: "请输入楼层"
  }, {
    label: '总楼层',
    key: 'total_floor',
    type: 'text',
    required: true,
    border: true,
    placeholder: "请输入楼层"
  }, {
    label: '建筑面积',
    key: 'space',
    type: 'text',
    border: true,
    required: true,
    suffix: '平米',
    placeholder: "请输入建筑面积"
  }, {
    label: '期望价格',
    key: 'price',
    type: 'text',
    border: true,
    required: true,
    suffix: '元',
    placeholder: "请输入期望价格"
  }, {
    label: '房源图片',
    key: 'images',
    type: 'upload',
    required: true,
    border: true,
    labelPosition: 'top',
    remark: '123',
    placeholder: '请上传图片'
  }, {
    label: '房源视频',
    key: 'video',
    type: 'uploadVideo',
    required: true,
    border: true,
    labelPosition: 'top',
    placeholder: '请上传视频'
  }, {
    label: '联系人',
    key: 'real_name',
    type: 'text',
    required: true,
    border: true,
    placeholder: "请输入联系人",
    radio: true,
  }, {
    label: '联系电话',
    key: 'user_phone',
    type: 'text',
    border: true,
    required: true,
    placeholder: "请输入联系电话"
  }, ])
  onMounted(() => {
    _houseOption()
  })
  // 我要卖房
  const handleSubmit = (form) => {
    delete form.house_type_text
    sell_house(form).then(res => {
      uni.$u.toast(res.msg)
      setTimeout(() => {
        uni.navigateBack()
      }, 500)
    })
  }

  // 获取小区户型
  const _houseOption = () => {
    houseOption().then(res => {
      formJson.value[4].selectList = res.data.house_type
    })
  }
</script>

<style scoped lang="scss">
  .home {
    padding: 0 24rpx;
    padding-bottom: calc(200rpx + env(safe-area-inset-bottom));
    min-height: 100vh;
    background: #fff;

    ::v-deep .u-input {
      background: #fff !important;
    }
  }

  ::v-deep .u-form-item__body__left__content__label {
    font-size: 30rpx !important;
    font-weight: 500;
  }

  ::v-deep .u-form-item__body {
    padding: 35rpx 0 !important;
  }

  ::v-deep .u-form-item__body__left__content__required {
    left: auto !important;
    right: -12rpx;
  }
</style>